<?php


namespace plugin\exportcenter\app\strategy;

use plugin\exportcenter\app\logic\Export;
use plugin\exportcenter\app\service\CsvExport;
use think\facade\Db;

class UserExport extends Export
{
    public $action = "user";

    public function export($id, $data)
    {
        $export_params = json_decode($data['export_params'], true);
        $table = $export_params['table'];
        $where = $export_params['where'];
        $header = [
            "用户名" => "username",
            "昵称" => "nickname",
            "电子邮箱" => "email",
            "手机号" => "mobile",
            "余额" => "balance",
        ];
        $csv = new CsvExport;
        $csv->setHeader($header);
        Db::table($table)->where($where)->chunk(10000, function ($res) use ($csv) {
            $csv->batchExport($res);
        });
        //上传到oss
        return $this->uploadOss($csv->getPath());
    }
}